package com.clf.springCloudAccount.controller;

import com.clf.account.User;
import com.clf.common.vo.Result;
import com.clf.common.vo.Search;
import com.clf.springCloudAccount.service.UserService;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Author: chenglongfei
 * @date: 2022/7/14
 * @Description UserController
 */
@RestController
@RequestMapping("/api")
public class UserController {
    @Autowired
    private UserService userService;

    /**
     * 127.0.0.1/api/login ---- post
     * {"userName":"admin","password":"111111"}
     */
    @PostMapping(value = "/login", consumes = "application/json")
    public Result<User> login(@RequestBody User user) {
        return userService.login(user);
    }

    /**
     * 127.0.0.1/api/user ---- post
     */
    @PostMapping(value = "/user", consumes = "application/json")
    public Result<User> insertUser(@RequestBody User user) {
        return userService.insertUser(user);
    }

    /**
     * 127.0.0.1/api/user ---- put
     */
    @PutMapping(value = "/user", consumes = "application/json")
    public Result<User> updateUser(@RequestBody User user) {
        return userService.updateUser(user);
    }

    /**
     * 127.0.0.1/api/user/10 ---- delete
     */
    @DeleteMapping(value = "/user/{id}")
    public Result<Object> deleteUserById(@PathVariable int id) {
        return userService.deleteUserById(id);
    }

    /**
     * 127.0.0.1/api/user/10 ---- get
     */
    @GetMapping(value = "/user/{id}")
    public User getUserById(@PathVariable int id) {
        return userService.getUserById(id);
    }

    /**
     * 127.0.0.1/api/users ---- post
     */
    @PostMapping(value = "/users", consumes = "application/json")
    public PageInfo<User> getUsersBySearch(@RequestBody Search search) {
        return userService.getUsersBySearch(search);
    }
}
